﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using JM.JCY.BusinessEntity;
using JM.JCY.Proxy;
using NCS.IConnect.ApplicationContexts;
using JM.JCY.Common;
using JM.JCY.Common.Utilities;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.IncorruptArchives.PersonImportantReportView
{
    public partial class PersonImportantReportViewUserControl : UserControl
    {
        public int _caseId
        {
            set { ViewState["_caseId"] = value; }
            get { return (int)ViewState["_caseId"]; }
        }

        public string _isApproval
        {
            set { ViewState["_isApproval"] = value; }
            get { return (string)ViewState["_isApproval"]; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (IncorruptProxy proxy = new IncorruptProxy())
                {
                    if (Request.QueryString["CaseId"] != null)
                    {
                        _caseId = Int32.Parse(Request.QueryString["CaseId"].ToString());
                        _isApproval = Request.QueryString["IsApproval"].ToString();
                    }

                    var loadDT = proxy.GetPersonImportantReport(_caseId, string.Empty);
                    LoadForView(loadDT);
                    LoadForEdit(loadDT);
                }

            }

            // switch controls
            if (this.hfIsEdit.Value != "1")
                SwitchControls(true, false);
            else
                SwitchControls(false, true);
        }

        private void SwitchControls(bool isLabelsShow, bool isControlsShow)
        {
            // Labels
            this.lblApproval.Visible = isLabelsShow;
            this.lblContent_Reason.Visible = isLabelsShow;
            this.lblDept_Position.Visible = isLabelsShow;
            this.lblPoliticSituation.Visible = isLabelsShow;
            this.lblReportDate.Visible = isLabelsShow;
            this.lblReporter.Visible = isLabelsShow;

            //Controls
            this.txtApproval.Visible = isControlsShow;
            this.txtContent_Reason.Visible = isControlsShow;
            this.txtDept_Position.Visible = isControlsShow;
            this.txtPoliticSituation.Visible = isControlsShow;
            this.dtReportDate.Visible = isControlsShow;
            this.txtReporter.Visible = isControlsShow;
            this.hr4.Visible = isControlsShow;
        }

        private void LoadForView(IncorruptDataSet.T_PersonImportantReportDataTable dt)
        {
            var loadRow = dt[0];
            this.lblApproval.Text = loadRow.Approval;
            this.lblContent_Reason.Text = loadRow.Content_Reason;
            this.lblDept_Position.Text = loadRow.Dept_Position;
            this.lblPoliticSituation.Text = loadRow.PoliticSituation;
            this.lblReportDate.Text = loadRow.ReportDate.ToString(JCYConstant.Date_Format_CN);
            this.lblReporter.Text = loadRow.Reporter;


        }

        private void LoadForEdit(IncorruptDataSet.T_PersonImportantReportDataTable dt)
        {
            var loadRow = dt[0];

            this.txtApproval.Text = loadRow.Approval;
            this.txtContent_Reason.Text = loadRow.Content_Reason;
            this.txtDept_Position.Text = loadRow.Dept_Position;
            this.txtPoliticSituation.Text = loadRow.PoliticSituation;
            this.hfReportDate.Value = loadRow.ReportDate.ToString();
            this.txtReporter.Text = loadRow.Reporter;
        }
    }
}
